-
Notifications
You must be signed in to change notification settings - Fork 25
第10回Go勉強会の課題@luccafort #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
sleep_sortディレクトリの実装をerrgourp#Groupとerrgroup#Waitを用いてGoroutineの終了を同期するよう変更 実行したgoroutine内でエラーが発生したときのハンドリングを実装
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
気になったところや考えてたことなどをコメント。
) | ||
|
||
// mutex | ||
var mu sync.Mutex | ||
var sortedNums []int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[コメント]
そういえば今回グローバル領域に変数を定義したわけだけど個人的にはあまりグローバル領域に変数を定義したくないわけで、じゃあどうすればいいのか?ってところまで突き詰められてなかった。
defer mu.Unlock() | ||
sortedNums = append(sortedNums, n) | ||
}(num) // (num)が無名関数の引数 | ||
eg.Go(SleepLessThan100(num)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[コメント]
この eg.Go
でラップするのが少し気になった。
JSのように async / await
な構文が欲しくなったけどそれだと多分隠蔽しすぎてるという思想なのかなと思った。
JSのように動的言語であればそっちのほうが嬉しいけど型のある世界でそれを隠蔽してしまうと副作用も隠蔽することになるので明示的に宣言させてそうだなって思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あとJSと違って複数のGoroutineの終了を同期したい、みたいな要件も違ってるだろうなというのがある。
} | ||
|
||
// SleepLessThan100 using SleepSort and return error when variable more than 100. | ||
func SleepLessThan100(n int) func() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[コメント]
戻り値の型指定で func() error
を返すというのがどうにも違和感がある。
ただこれは慣れの問題かなと思ってる。
return errors.New("n must be less than 100") | ||
} | ||
// n秒スリープする | ||
time.Sleep(time.Duration(n) * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[コメント]
Sleep Sortというソートの概念知らなかった。
知らないアルゴリズムだったのでめちゃくちゃ難しいことしてるのか!?と思ったら逆だったのウケる
|
||
func init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
雰囲気で特殊な組み込み関数をオーバーライドしていてmain関数の実行前に初期化処理が行えるんだろうな、くらいに考えてた。
https://qiita.com/tenntenn/items/7c70e3451ac783999b4f
課題
https://mf.esa.io/posts/132264